package com.ruoyi.novel.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.novel.domain.Novels;
import com.ruoyi.novel.service.INovelsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 小说Controller
 * 
 * @author sjy
 * @date 2025-06-05
 */
@RestController
@RequestMapping("/novel/novels")
public class NovelsController extends BaseController
{
    @Autowired
    private INovelsService novelsService;

    /**
     * 查询小说列表
     */
    @PreAuthorize("@ss.hasPermi('novel:novels:list')")
    @GetMapping("/list")
    public TableDataInfo list(Novels novels)
    {
        startPage();
        List<Novels> list = novelsService.selectNovelsList(novels);
        return getDataTable(list);
    }

    /**
     * 导出小说列表
     */
    @PreAuthorize("@ss.hasPermi('novel:novels:export')")
    @Log(title = "小说", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Novels novels)
    {
        List<Novels> list = novelsService.selectNovelsList(novels);
        ExcelUtil<Novels> util = new ExcelUtil<Novels>(Novels.class);
        util.exportExcel(response, list, "小说数据");
    }

    /**
     * 获取小说详细信息
     */
    @PreAuthorize("@ss.hasPermi('novel:novels:query')")
    @GetMapping(value = "/{novelId}")
    public AjaxResult getInfo(@PathVariable("novelId") Long novelId)
    {
        return success(novelsService.selectNovelsByNovelId(novelId));
    }

    /**
     * 新增小说
     */
    @PreAuthorize("@ss.hasPermi('novel:novels:add')")
    @Log(title = "小说", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Novels novels)
    {
        return toAjax(novelsService.insertNovels(novels));
    }

    /**
     * 修改小说
     */
    @PreAuthorize("@ss.hasPermi('novel:novels:edit')")
    @Log(title = "小说", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Novels novels)
    {
        return toAjax(novelsService.updateNovels(novels));
    }

    /**
     * 删除小说
     */
    @PreAuthorize("@ss.hasPermi('novel:novels:remove')")
    @Log(title = "小说", businessType = BusinessType.DELETE)
	@DeleteMapping("/{novelIds}")
    public AjaxResult remove(@PathVariable Long[] novelIds)
    {
        return toAjax(novelsService.deleteNovelsByNovelIds(novelIds));
    }
}
